const Order = require('../model/order.model')

class OrderService {
    async createOrder(data){
        // console.log(data);
        
        
        return await Order.create(data)
    }

    async findAllOrder(pageNum,pageSize,status){
        const {count,rows} = await Order.findAndCountAll({
            attributes:['goods_info','total','order_number','status'],
            where:{
                status
            },
            offset:(pageNum-1)*pageSize,
            limit: pageSize * 1
        })

        return{
            pageNum,
            pageSize,
            status,
            total:count,
            list:rows
        }
    }
    async updateOrder(id,status){
        return await Order.update({status},{
            where:{id}
        })
    }
}

module.exports = new OrderService()